using System;
using System.Collections.Generic;
using System.Text;
using JBORPG.Net.Attributes;
using JBORPG.Net.Classes;
using System.Data.SqlClient;

namespace JBORPG.Server.Handlers
{
    [NetClass()]
    public class PlayerHandler
    {
        [NetMethod()]
        public Boolean RegisterUser(String username, String password)
        {
            return false;
        }

        [NetMethod()]
        public Player Login(String username, String password)
        {
            Player p = new Player();
            SqlDataReader reader = Database.Instance.Query("SELECT * FROM tblPlayers WHERE Username = @username AND Password = @password", new SqlParameter("@username", username), new SqlParameter("@password", password));

            reader.Read();
            if (reader.HasRows)
            {
                
                RoomHandler rh = new RoomHandler();
                
                p.Username = (String)reader["Username"];
                p.Password = (String)reader["Password"];
                p.Level = (Int32)reader["Level"];
                p.BaseStrength = (Int32)reader["BaseStrength"];
                Int32 rid = (Int32)reader["rId"];
                reader.Close();
                p.Room = rh.GetRoom(rid);
                return p;
            }
            else
            {
                throw new Exception("Player not found!");
            }
        }
    }
}
